package com.jason.hadoop.reduce;

import com.jason.hadoop.bean.WordBean;
import com.jason.hadoop.bean.WordOrderBean;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

public class WordOrderReduce extends Reducer<WordBean, NullWritable, WordOrderBean, NullWritable> {
    @Override
    protected void reduce(WordBean key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        int i = 1;
        Iterator<NullWritable> iterator = values.iterator();
        while (iterator.hasNext()) {
            WordOrderBean orderBean = new WordOrderBean();
            orderBean.setOrder(i);
            orderBean.setNum(key.getNum());
            context.write(orderBean, NullWritable.get());
            iterator.next();
            i ++;
        }
    }
}
